/**
 * @description router全局配置，如有必要可分文件抽离
 */

import Vue from "vue";
import VueRouter from "vue-router";
import Layout from "@/layouts";
import EmptyLayout from "@/layouts/EmptyLayout";
import { publicPath, routerMode } from "@/config/settings";

Vue.use(VueRouter);

export const constantRoutes = [
	{
		path: "/login",
		component: () => import("@/views/login/index"),
		hidden: true,
	},
	{
		path: "/register",
		component: () => import("@/views/register/index"),
		hidden: true,
	},
	{
		path: "/401",
		name: "401",
		component: () => import("@/views/401"),
		hidden: true,
	},
	{
		path: "/404",
		name: "404",
		component: () => import("@/views/404"),
		hidden: true,
	},

];

/*当settings.js里authentication配置的是intelligence时，views引入交给前端配置*/
export const asyncRoutes = [
	{
		path: "/",
		component: Layout,
		redirect: "/index",
		children: [
			{
				path: "/index",
				name: "Index",
				component: () => import("@/views/index/index"),
				meta: {
					title: "首页",
					icon: "home",
					affix: true,
					noKeepAlive: true,
				},
			},
		],
	},
	{
		path: "/personalCenter",
		component: Layout,
		hidden: true,
		redirect: "personalCenter",
		children: [
			{
				path: "personalCenter",
				name: "PersonalCenter",
				component: () => import("@/views/personalCenter/index"),
				meta: {
					title: "个人中心",
				},
			},
		],
	},

	{
		path: "/system",
		component: Layout,
		redirect: "noRedirect",
		name: "System",
		alwaysShow: true,
		meta: { title: "系统设置", icon: "box-open" },
		children: [
			{
				path: "systematic",
				component: EmptyLayout,

				name: "Systematic",
				meta: {
					title: "权限管理",
					permissions: ["admin"],
				},
				children: [
					{
						path: "role",
						name: "Role",
						component: () => import("@/views/system/systematic/role"),
						meta: { title: "角色管理" },
					},
					{
						path: "mechanism",
						name: "Mechanism",
						component: () => import("@/views/system/systematic/mechanism"),
						meta: { title: "机构管理" },
					},
					{
						path: "shortages",
						name: "shortages",
						component: () => import("@/views/system/systematic/shortages"),
						meta: { title: "资源管理" },
					},
					{
						path: "personnel",
						name: "Personnel",
						component: () => import("@/views/system/systematic/personnel"),
						meta: { title: "人员管理" },
					},
				],

			},


			{
				path: "berth",
				component: EmptyLayout,
				redirect: "noRedirect",
				name: "Berth",
				meta: {
					title: "床位设置",
					permissions: ["admin"],
				},
				children: [
					{
						path: "berth",
						name: "Berth",
						component: () => import("@/views/system/berth/berth"),
						meta: { title: "床位管理" },
					},
					{
						path: "room",
						name: "Room",
						component: () => import("@/views/system/berth/room"),
						meta: { title: "房间管理" },
					},
					{
						path: "storied",
						name: "Storied",
						component: () => import("@/views/system/berth/storied"),
						meta: { title: "楼宇管理" },
					},

				],

			},
      {
        path: "mechanism",
        name: "Mechanism",
        alwaysShow: true,

        component: () => import("@/views/system/mechanism/index"),
        meta: {
          title: "机构设置",

        },


      },
      {
        path: "hospital",
        name: "Hospital",
        alwaysShow: true,

        component: () => import("@/views/system/hospital/index"),
        meta: {
          title: "病区管理",

        },


      },
			{
				path: "dictionary",
				name: "Dictionary",
				alwaysShow: true,

				component: () => import("@/views/system/dictionary/index"),
				meta: {
					title: "系统字典",

				},


			},
			{
				path: "itemmanager",
				component: EmptyLayout,
				redirect: "noRedirect",
				name: "Itemmanager",
				meta: {
					title: "项目管理",
					permissions: ["admin"],
				},
				children: [
					{
						path: "category",
						name: "Category",
						component: () => import("@/views/system/itemmanager/category"),
						meta: { title: "类目设置" },
					},
					{
						path: "meal",
						name: "Meal",
						component: () => import("@/views/system/itemmanager/meal"),
						meta: { title: "套餐设置" },
					},


				],

			},
			{
				path: "nurse",
				name: "Nurse",
				alwaysShow: true,

				component: () => import("@/views/system/dictionary/nurse"),
				meta: {
					title: "护理等级",

				},


			},
			{
				path: "roomtype",
				name: "Roomtype",
				alwaysShow: true,

				component: () => import("@/views/system/dictionary/roomtype"),
				meta: {
					title: "房间类型",

				},


			},
			]
	},
	{
		path: "/reception",
		component: Layout,
		redirect: "noRedirect",
		name: "reception",
		alwaysShow: true,
		meta: { title: "接待管理", icon: "box-open" },
		children: [
			{
				path: "advisory",
				component: () => import("@/views/reception/advisory"),
				name: "advisory",
				meta: {
					title: "接待咨询",
					permissions: ["admin"],
				}

			},
			{
				path: "roomstate",
				component: () => import("@/views/reception/roomstate"),
				name: "roomstate",
				meta: {
					title: "房态图",
					permissions: ["admin"],
				}

			},
		]
	},
	{
		path: "/feemanager",
		component: Layout,
		redirect: "noRedirect",
		name: "feemanager",
		alwaysShow: true,
		meta: { title: "费用管理", icon: "box-open" },
		children: [
			{
				path: "account",
        name: "Account",
				component: () => import("@/views/feemanager/account"),

				meta: {
					title: "入住账户管理",
					permissions: ["admin"],
				}

			},
			{
				path: "bill/:checkinmarkrouter?",
				component: () => import("@/views/feemanager/bill"),
				name: "bill",
				meta: {
					title: "费用管理",
					permissions: ["admin"],
				}

			},

      {
        path: "billmanagement",
        component: () => import("@/views/feemanager/billmanagement"),
        name: "Billmanagement",
        meta: {
          title: "费用管理",
          permissions: ["admin"],
        }

      },

    ]
	},
	{
		path: "/support",
		component: Layout,
		redirect: "noRedirect",
		name: "Support",
		alwaysShow: true,
		meta: { title: "护工管理", icon: "user-clock" },
		children: [
			{
				path: "staff",

				component: () => import("@/views/support/staff"),
				name: "Staff",
				meta: {
					title: "护工设置",
					permissions: ["admin"],
				},


			},

			{
				path: "volunteer",
				component: () => import("@/views/support/volunteer"),

				name: "volunteer",
				meta: {
					title: "志愿者设置",
					permissions: ["admin"],
				},


			},
      {
        path: "doctor",
        component: () => import("@/views/support/doctor"),

        name: "Doctor",
        meta: {
          title: "医生管理",
          permissions: ["admin"],
        },


      },



		]
	},
	{
		path: "/archives",
		component: Layout,
		redirect: "noRedirect",
		name: "Archives",
		alwaysShow: true,
		meta: { title: "老人档案", icon: "file-contract" },
		children: [
			{
				path: "basicarchives",

				component: () => import("@/views/archives/basicarchives"),
				name: "Basicarchives",
				meta: {
					title: "基础档案",
					permissions: ["admin"],
				},


			},
      {
        path: "medicalcheckup",

        component: () => import("@/views/archives/medicalcheckup/index"),
        name: "Medicalcheckup",
        meta: {
          title: "健康监测",
          permissions: ["admin"],
        },


      },





		]
	},
	{
		path: "/move",
		component: Layout,
		redirect: "move",
		name: "Move",
		alwaysShow: true,
		meta: { title: "入住管理", icon: "users-cog" },
		children: [
			{
				path: "moveset",
				component: () => import("@/views/move/moveset"),
				name: "Moveset",
				meta: {
					title: "办理入住",
					permissions: ["admin"],
				},


			},

			{
				path: "reserve",
				component: () => import("@/views/move/reserve"),

				name: "Reserve",
				meta: {
					title: "床位预定",
					permissions: ["admin"],
				},


			},

      {
        path: "tasteorgan",
        component: () => import("@/views/move/tasteorgan"),
        name: "Tasteorgan",
        meta: {
          title: "兴趣小组管理",
          permissions: ["admin"],
        },


      },

      {
        path: "disease",
        component: () => import("@/views/move/disease"),
        name: "Disease",
        meta: {
          title: "传染病登记",
          permissions: ["admin"],
        },


      },
      {
        path: "visit",
        component: () => import("@/views/move/visit"),
        name: "Visit",
        meta: {
          title: "来访探视登记",
          permissions: ["admin"],
        },


      },
      {
        path: "egress",
        component: () => import("@/views/move/egress"),
        name: "Egress",
        meta: {
          title: "外出登记",
          permissions: ["admin"],
        },


      },
      {
        path: "malfunction",
        component: () => import("@/views/move/malfunction"),
        name: "Malfunction",
        meta: {
          title: "事故单记录管理",
          permissions: ["admin"],
        },


      },
		]
	},
	{
		path: "/nursing",
		component: Layout,
		redirect: "noRedirect",
		name: "Nursing",
		alwaysShow: true,
		meta: { title: "护理设置", icon: "file-contract" },
		children: [
			{
				path: "record",
				component: () => import("@/views/nursing/record"),
				name: "Record",
				meta: {
					title: "护理记录",
					permissions: ["admin"],
				},
			},
			{
				path: "template",
				component: () => import("@/views/nursing/template"),
				name: "Template",
				meta: {
					title: "护理计划模板",
					permissions: ["admin"],
				},
			},
      {
        path: "turnoverrecords",
        component: () => import("@/views/nursing/Turnoverrecords"),
        name: "Turnoverrecords",
        meta: {
          title: "翻身记录",
          permissions: ["admin"],
        },
      },


    ]
	},
	{
		path: "/assessment",
		component: Layout,
		redirect: "noRedirect",
		name: "Assessment",
		alwaysShow: true,
		meta: { title: "评估管理", icon: "file-contract" },
		children: [
			{
				path: "records",
				component: () => import("@/views/assessment/records"),
				name: "AssessmentRecord",
				meta: {
					title: "评估记录",
					permissions: ["admin"],
				},
			},
		]
	},
	{
		path: "*",
		redirect: "/404",
		hidden: true,
	},

];

const router = new VueRouter({
	base: routerMode === "history" ? publicPath : "",
	mode: routerMode,
	scrollBehavior: () => ({
		y: 0,
	}),
	routes: constantRoutes,
});
//注释的地方是允许路由重复点击，如果你觉得框架路由跳转规范太过严格可选择放开
/* const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
	if (onResolve || onReject)
		return originalPush.call(this, location, onResolve, onReject);
	return originalPush.call(this, location).catch((err) => err);
}; */

export function resetRouter() {
	router.matcher = new VueRouter({
		base: routerMode === "history" ? publicPath : "",
		mode: routerMode,
		scrollBehavior: () => ({
			y: 0,
		}),
		routes: constantRoutes,
	}).matcher;
}

export default router;
